package com.leyou.order.controller;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.entity.Order;
import com.leyou.order.service.OrderService;
import com.leyou.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author syf
 * @version 1.0
 * @date 2019/08/18 16:34
 * @Description TODO:订单微服务控制器
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //创建订单
    @PostMapping
    public ResponseEntity<Long> cartOrderId(@RequestBody OrderDTO orderDTO){
        Long orderId = orderService.cartOrderId(orderDTO);
        return ResponseEntity.ok(orderId);
    }

    //查询订单
    @GetMapping("/{id}")
    public ResponseEntity<OrderVO> queryOrderById(@PathVariable("id") Long id){
        return ResponseEntity.ok(orderService.queryOrderById(id));
    }

    //生成支付链接
    @GetMapping("/url/{id}")
    public ResponseEntity<String> createWxUrl(@PathVariable("id") Long id){
        return ResponseEntity.ok(orderService.createWxUrl(id));
    }

    //支付状态查询
    @GetMapping("/state/{id}")
    public ResponseEntity<Integer> queryPayState(@PathVariable("id") Long orderId) {
        return ResponseEntity.ok(orderService.queryPayStatus(orderId));
    }

}
